package com.wuliu.common.core.domain;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.github.pagehelper.Page;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import java.io.Serializable;
import java.util.List;


/**
 * @author realue
 * @version 1.0
 * @date 2023-08-09 21:50
 */
@Data
@ApiModel("分页返回实体类")
public class PageResult<T> implements Serializable {

    private static final long serialVersionUID = 1L;

    @ApiModelProperty(value = "总记录数")
    private int total = -1;
    @ApiModelProperty(value = "当前页码")
    private int pageNo = 1;
    @ApiModelProperty(value = "每页记录数")
    private int pageSize = 10;
    @ApiModelProperty(value = "总页数")
    private int pages;
    @ApiModelProperty(value = "结果集")
    private List rows;

    public PageResult() {

    }

    public PageResult(Page<T> page) {

        total = (int) page.getTotal();

        pageNo = page.getPageNum();

        pageSize = page.getPageSize();

        pages = page.getPages();

        rows = page.getResult();

    }

    public PageResult(Page<T> page, List<T> dataList) {

        total = (int) page.getTotal();

        pageNo = page.getPageNum();

        pageSize = page.getPageSize();

        pages = page.getPages();

        rows = dataList;

    }

    public PageResult(IPage<T> iPage) {
        total = (int) iPage.getTotal();

        pageNo = (int) iPage.getCurrent();

        pageSize = (int) iPage.getSize();

        pages = (int) iPage.getPages();

        rows = iPage.getRecords();
    }

    public PageResult(IPage<T> iPage,List<T> dataList) {
        total = (int) iPage.getTotal();

        pageNo = (int) iPage.getCurrent();

        pageSize = (int) iPage.getSize();

        pages = (int) iPage.getPages();

        rows = dataList;
    }
}
